package com.changgou.service.goods.handler;

import com.changgou.common.pojo.CustomException;
import com.changgou.common.pojo.Result;
import com.changgou.common.pojo.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description: 统一异常处理类
 * @Author: JoinCao
 * @CreateDate: 2020-03-14
 * @UpdateUser: JoinCao
 * @UpdateDate: 2020-03-14
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@ControllerAdvice//声明该类是一个增强类
public class BaseExceptionHandler {
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result error(Exception e) {
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR, "当前系统繁忙,请稍后再试");
    }

    @ExceptionHandler(value = CustomException.class)//扫描异常的类型
    @ResponseBody
    public Result error(CustomException e) {
        e.printStackTrace();
        return e.getResult();
    }
}
